package pers.qianyu.diytomcat.catalina;

import javax.servlet.*;
import java.util.*;

/**
 * @author mizzle rain
 * @date 2021-01-16 15:16
 */
public class StandardFilterConfig implements FilterConfig {
    private String filterName;
    private ServletContext servletContext;
    private Map<String, String> initParameters;

    public StandardFilterConfig(String filterName, ServletContext servletContext, Map<String, String> initParameters) {
        this.filterName = filterName;
        this.servletContext = servletContext;
        this.initParameters = initParameters;
        if (Objects.isNull(initParameters)) {
            this.initParameters = new HashMap<>();
        }
    }

    @Override
    public String getFilterName() {
        return filterName;
    }

    @Override
    public ServletContext getServletContext() {
        return servletContext;
    }

    @Override
    public String getInitParameter(String s) {
        return initParameters.get(s);
    }

    @Override
    public Enumeration<String> getInitParameterNames() {
        return Collections.enumeration(initParameters.keySet());
    }

    public void setFilterName(String filterName) {
        this.filterName = filterName;
    }

    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }

    public Map<String, String> getInitParameters() {
        return initParameters;
    }

    public void setInitParameters(Map<String, String> initParameters) {
        this.initParameters = initParameters;
    }
}
